﻿Imports System.Linq
Imports DAL
Module VariablesGlobales
    Public bd As New BDCarpeDiemDataContext
    Public interet As New Hashtable
    Public empConnecte As utilisateur

    Function SpacesBeforeCaps(strIn As String) As String
        Dim intI As Integer = 0
        Dim strTemp As String = ""

        Do
            intI = intI + 1
            If UCase(Mid(strIn, intI, 1)) = Mid(strIn, intI, 1) And Not intI = 1 Then
                strTemp = strTemp & " " & Mid(strIn, intI, 1)
            Else
                strTemp = strTemp & Mid(strIn, intI, 1)
            End If

        Loop Until Len(strIn) = intI

        Return strTemp
    End Function

    Function CouleurContraste(ByVal col As Color) As Color
        Return IIf(((col.R * 517) + (col.G * 587) + (col.B * 60)) / 1000 >= 131.5, Color.Black, Color.White)
    End Function

    Public Function SimpleCrypt(ByVal Text As String) As String
        ' Encrypts/decrypts the passed string using 
        ' a simple ASCII value-swapping algorithm
        Dim strTempChar As String = "", i As Integer
        For i = 1 To Len(Text)
            If Asc(Mid$(Text, i, 1)) < 128 Then
                strTempChar = CType(Asc(Mid$(Text, i, 1)) + 128, String)
            ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
                strTempChar = CType(Asc(Mid$(Text, i, 1)) - 128, String)
            End If
            Mid$(Text, i, 1) = Chr(CType(strTempChar, Integer))
        Next i
        Return Text
    End Function

    Public Sub PrintPlageInsert()
        For Each ins In bd.PlageHoraires.Context.GetChangeSet().Inserts
            If ins.GetType() Is GetType(PlageHoraire) Then
                Console.WriteLine("insert " + ins.Nom + " id = " + ins.ID.ToString)
            End If
            If ins.GetType() Is GetType(Tache) Then
                Console.WriteLine("insert " + ins.Nom + " id = " + ins.ID.ToString)
            End If
        Next
    End Sub
    Public Sub PrintPlageDelete()
        For Each ins In bd.PlageHoraires.Context.GetChangeSet().Deletes
            If ins.GetType() Is GetType(PlageHoraire) Then
                Console.WriteLine("delete " + ins.Nom + " id = " + ins.ID.ToString)
            End If
            If ins.GetType() Is GetType(Tache) Then
                Console.WriteLine("delete " + ins.Nom + " id = " + ins.ID.ToString)
            End If
        Next
    End Sub



End Module

Structure utilisateur
    Dim id, gestionBeneficiaire, gestionEmploye, gestionHoraire As Integer
    Dim nom As String
End Structure